package com.jcfk.eam.controller.bd;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.eam.domain.dto.base.EamTeamMemberAbilityDTO;
import com.jcfk.eam.domain.query.base.EamTeamMemberAbilityQuery;
import com.jcfk.eam.service.base.EamTeamMemberAbilityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.common.core.utils.ExcelUtils;
/**
 * 班组成员能力
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-08-18
 */
@Api(tags = {"班组成员能力管理"})
@RestController
@RequestMapping("eamMemberAbility")
public class EamTeamMemberAbilityController {
    @Autowired
    private EamTeamMemberAbilityService eamTeamMemberAbilityService;

    /**
     * 分页列表
     */
    @ApiOperation("分页查询班组成员能力")
    @PostMapping("/queryByPage")
    public RetPage<EamTeamMemberAbilityDTO> queryByPage(@RequestBody ReqPageParam<EamTeamMemberAbilityQuery> requestParam) {
        DataPage<EamTeamMemberAbilityDTO> page = new DataPage<EamTeamMemberAbilityDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamTeamMemberAbilityDTO.class);
        page = eamTeamMemberAbilityService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  班组成员能力
     * 根据id 查询详情
     */
    @ApiOperation("查询班组成员能力")
    @GetMapping("/get/{id}")
    public RetResult<EamTeamMemberAbilityDTO> get(@PathVariable("id") String id) {
            EamTeamMemberAbilityDTO item = eamTeamMemberAbilityService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理班组成员能力
     */
    @ApiOperation("保存班组成员能力")
    @PostMapping("/save")
    @RequestLogHeader(modular = "班组成员能力管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamTeamMemberAbilityDTO eamTeamMemberAbility) {
        // 数据校验
        RetResult ret = eamTeamMemberAbilityService.isValid(eamTeamMemberAbility);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamTeamMemberAbility.getId())){
            // 新增
            eamTeamMemberAbilityService.insert(eamTeamMemberAbility);
        } else{
            // 更新
            eamTeamMemberAbilityService.update(eamTeamMemberAbility);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除班组成员能力
     */
    @ApiOperation("批量删除班组成员能力")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "班组成员能力管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamTeamMemberAbilityDTO eamTeamMemberAbility) {
        return RetResult.ok(eamTeamMemberAbilityService.logicDeleteList(eamTeamMemberAbility));
    }

    /**
     *  删除班组成员能力
     */
    @ApiOperation("删除班组成员能力")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "班组成员能力管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamTeamMemberAbilityService.deleteItem(id);
        return RetResult.ok();
    }
}
